#
# @lc app=leetcode.cn id=860 lang=python3
#
# [860] 柠檬水找零
#
"""
思路：统计5和10出现的频数，然后依次找零
"""

# @lc code=start
class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        five = 0
        ten = 0
        flag = True
        for i in range(len(bills)):
            if bills[i] == 5:
                five += 1
                continue
            elif bills[i] == 10:
                if five == 0:
                    flag =  False
                else:
                    five -= 1
                ten += 1
            else:
                if ten == 0:
                    if five < 3:
                        flag =  False
                    else:
                        five -= 3
                else:
                    if five == 0:
                        flag =  False
                    else:
                        ten -= 1
                        five -= 1
            if not flag:
                break
        return flag

# @lc code=end

